package com.zxm.edu.controller;


import com.zxm.edu.annotation.OptLog;
import com.zxm.edu.entity.School;
import com.zxm.edu.service.SchoolService;
import com.zxm.edu.vo.ConditionVO;
import com.zxm.edu.vo.PageResult;
import com.zxm.edu.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

import static com.zxm.edu.constant.OptTypeConst.REMOVE;
import static com.zxm.edu.constant.OptTypeConst.SAVE_OR_UPDATE;


/**
 * 院校控制器
 *
 * @author silencezheng
 * @date 2021/07/29
 */
@Api(tags = "院校模块")
@RestController
public class SchoolController {
    @Autowired
    private SchoolService schoolService;

    /**
     * 查询院校列表
     */
    @ApiOperation(value = "查询院校列表")
    @GetMapping("/school/list")
    public Result<PageResult<School>> listSchools(ConditionVO condition) {
        return Result.ok(schoolService.listSchools(condition));
    }

    /**
     * 查询后台院校列表
     *
     * @param condition 条件
     */
   /* @ApiOperation(value = "查询后台院校列表")
    @GetMapping("/admin/school")
    public Result<PageResult<School>> listSchoolBack(ConditionVO condition) {
        return Result.ok(schoolService.listSchoolBackDTO(condition));
    }

    *//**
     * 搜索资讯院校
     *
     * @param condition 条件
     * @return {@link Result<String>} 院校列表
     *//*
    @ApiOperation(value = "搜索资讯院校")
    @GetMapping("/school/search")
    public Result<List<School>> listSchoolsBySearch(ConditionVO condition) {
        return Result.ok(schoolService.listSchoolsBySearch(condition));
    }
*/
    /**
     * 添加或修改院校
     *
     * @return {@link Result<>}
     */
    @OptLog(optType = SAVE_OR_UPDATE)
    @ApiOperation(value = "添加或修改院校")
    @PostMapping("/admin/school")
    public Result<?> saveOrUpdateSchool(@Valid @RequestBody School school) {
        schoolService.saveOrUpdateSchool(school);
        return Result.ok();
    }

    /**
     * 删除院校
     *
     * @return {@link Result<>}
     */
    @OptLog(optType = REMOVE)
    @ApiOperation(value = "删除院校")
    @DeleteMapping("/admin/school")
    public Result<?> deleteSchool(@RequestBody List<Integer> schoolIdList) {
        schoolService.deleteSchool(schoolIdList);
        return Result.ok();
    }

}

